from odoo import fields, models, api


class StockPicking(models.Model):
    _inherit = 'stock.picking'
    consignment_id = fields.Many2one('consignment.sales', string='Consignment Sales')
    cs_owner_id = fields.Many2one('res.partner', string='Owner')

    # 处理取消操作
    # def action_cancel(self):
    #     res = super(StockPicking, self).action_cancel()
    #     if self.consignment_id:
    #         self.env['consignment.sales.line'].sudo().search([('sp_id', '=', self.id)]).write({'state': 'hole'})
    #     return res


class StockMoveLine(models.Model):
    _inherit = 'stock.move.line'
    owner_id = fields.Many2one(
        'res.partner', 'From Owner',
        check_company=True, index='btree_not_null',
        help="When validating the transfer, the products will be taken from this owner.",
        related='move_id.picking_id.owner_id', store=True
    )
